#include <iostream>
#include <functional>

void printHello() {
    std::cout << "Hello, world!" << std::endl;
}

int add(int a, int b) {
    return a + b;
}

struct Multiply {
    int operator()(int a, int b) {
        return a * b;
    }
};

int main() {
    std::function<void()> func1 = printHello;
    func1();  // 调用函数指针

    std::function<int(int, int)> func2 = add;
    int result = func2(3, 4);  // 调用函数
    std::cout << "Result: " << result << std::endl;

    Multiply multiply;
    std::function<int(int, int)> func3 = multiply;
    result = func3(3, 4);  // 调用函数对象
    std::cout << "Result: " << result << std::endl;

    auto lambda = [](int a, int b) { return a - b; };
    std::function<int(int, int)> func4 = lambda;
    result = func4(5, 2);  // 调用 lambda 表达式
    std::cout << "Result: " << result << std::endl;

    return 0;
}